package org.example.util;

import org.activiti.bpmn.model.ExtensionElement;
import org.activiti.engine.delegate.DelegateTask;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wanghuidong
 * 时间： 2024/6/26 17:14
 */
public class Activity7Util {

    /**
     * 获取扩展属性
     *
     * @param delegateTask 委托任务对象
     * @return 扩展属性Map
     */
    public Map<String, String> getExtensionProperties(DelegateTask delegateTask) {
        Map<String, String> properties = new HashMap<>();
        List<ExtensionElement> propertiesElements = delegateTask.getExecution().getCurrentFlowElement()
                .getExtensionElements().get("properties");
        if (propertiesElements != null && !propertiesElements.isEmpty()) {
            List<ExtensionElement> propertyElements = propertiesElements.get(0).getChildElements().get("property");
            if (propertyElements != null && !propertyElements.isEmpty()) {
                for (ExtensionElement propertyElement : propertyElements) {
                    String key = propertyElement.getAttributeValue(null, "name");
                    String val = propertyElement.getAttributeValue(null, "value");
                    val = val == null ? "" : val;
                    properties.put(key, val);
                }
            }
        }
        return properties;
    }
}